import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChangeAdminPasswordFrame extends JFrame {

    public ChangeAdminPasswordFrame() {
        setTitle("修改管理员密码");
        setSize(300, 200);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // 关闭时仅关闭当前窗口

        // 创建面板和布局
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(4, 2));
        add(panel);

        // 添加组件
        JLabel currentPasswordLabel = new JLabel("当前密码:");
        JTextField currentPasswordField = new JTextField();
        JLabel newPasswordLabel = new JLabel("新密码:");
        JPasswordField newPasswordField = new JPasswordField();
        JLabel confirmPasswordLabel = new JLabel("确认新密码:");
        JPasswordField confirmPasswordField = new JPasswordField();
        JButton saveButton = new JButton("保存");
        JButton cancelButton = new JButton("取消");

        panel.add(currentPasswordLabel);
        panel.add(currentPasswordField);
        panel.add(newPasswordLabel);
        panel.add(newPasswordField);
        panel.add(confirmPasswordLabel);
        panel.add(confirmPasswordField);
        panel.add(saveButton);
        panel.add(cancelButton);

        // 保存按钮事件监听器
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 获取输入的密码
                String newPassword = new String(newPasswordField.getPassword());
                String confirmPassword = new String(confirmPasswordField.getPassword());

                // 简单的密码匹配检查
                if (newPassword.equals(confirmPassword)) {
                    JOptionPane.showMessageDialog(null, "密码修改成功！");
                    dispose(); // 关闭当前窗口
                    new AdminMenuFrame().setVisible(true); // 返回管理员菜单界面
                } else {
                    JOptionPane.showMessageDialog(null, "新密码与确认密码不匹配！");
                }
            }
        });


        // 取消按钮事件监听器
        cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose(); // 关闭当前窗口
            }
        });
    }
}
